package com.sskj.login.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.login.bean.LoginBean;
import com.sskj.login.http.HttpConfig;
import com.sskj.login.ui.activity.LoginActivity;


public class LoginActivityPresenter extends BasePresenter<LoginActivity> {

    public void login(String areaCode, String account, String pwd, String type) {

        httpService.login(areaCode, account, pwd, type).execute(new JsonCallBack<HttpData<LoginBean>>(this) {
            @Override
            public void onSuccess(Response<HttpData<LoginBean>> response) {
                HttpData<LoginBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    if (httpData.getData().getIsGoogleOpenClose() == 0) {
                        mView.loginSuccess(httpData.getData());
                    } else {
                        mView.googleCheck(httpData.getData());
                    }
                }
            }
        });
    }


    public void checkGoogle(String code, LoginBean loginBean) {
        httpService.checkGoogle(code, loginBean.getId())
                .execute(new JsonCallBack<HttpData>(this) {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpData = response.body();
                        if (httpData.getStatus() == HttpConfig.OK) {
                            mView.checkSuccess(loginBean);
                        }
                    }
                });
    }



    /**
     * 登录成功，发送登录短信
     *
     * @param account
     */
    public void sendLoginSms(String account, String id, String token) {

        httpService.sendLoginSms(account, id, token)
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {

                    }
                });
    }
}
